use std::char::from_digit;

const ERR_MSG: &str = "Invalid input at solution2";
pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let mut tokens = num_str.trim().split(&['(', ')'][..]);
    let num = tokens.next().expect(ERR_MSG).trim();
    let base: u32 = tokens.next().expect(ERR_MSG).trim().parse().expect(ERR_MSG);
    let mut num = u32::from_str_radix(num, base).expect(ERR_MSG);
    if num == 0 {
        return "0".to_string();
    }
    let mut result = Vec::new();
    while num > 0 {
        result.push(from_digit(num % to_base, to_base).expect(ERR_MSG));
        num /= to_base;
    }
    result.iter().rev().collect()
}
